package com.hzdl.car.sqlprovider;

import com.hzdl.car.util.Common;
import com.hzdl.car.vo.CustomerVo;
import org.apache.ibatis.jdbc.SQL;

public class CustomerSqlProvider {
    public String findCustomer(CustomerVo customerVo){
        return new SQL(){{
            SELECT("*");
            FROM("bus_customer");
            if(!Common.isEmpty(customerVo.getIdentity())){
                WHERE("identity like concat('%',#{identity},'%')");
            }
            if(!Common.isEmpty(customerVo.getCustName())){
                WHERE("custName like concat('%',#{custName},'%')");
            }
            if(!Common.isEmpty(customerVo.getAddress())){
                WHERE("address like concat('%',#{address},'%')");
            }
            if(!Common.isEmpty(customerVo.getPhone())){
                WHERE("phone like concat('%',#{phone},'%')");
            }
            if(customerVo.getSex()!=null){
                WHERE("sex = #{sex}");
            }
            if(!Common.isEmpty(customerVo.getCareer())){
                WHERE("career like concat('%',#{career},'%')");
            }
            if(customerVo.getCreateTime1()!=null){
                WHERE("createTime >= #{createTime1}");
            }
            if(customerVo.getCreateTime2()!=null){
                WHERE("createTime <= #{createTime2}");
            }
            ORDER_BY("createTime desc");
        }}.toString();
    }
}
